package cn.zhqr.common.util.validate;

import java.security.InvalidParameterException;
import java.util.Collection;
import java.util.Map;

public class ParamCheck {
    public ParamCheck() {
    }

    public static void check(boolean expression, String message) {
        if (!expression) {
            throw new InvalidParameterException(message);
        }
    }

    public static void isNull(Object obj, String message) {
        check(obj == null, message);
    }

    public static void isNotNull(Object obj, String message) {
        check(obj != null, message);
    }

    public static void isNotBlank(String str, String message) {
        check(str != null && str.trim().length() > 0, message);
    }

    public static void isBlank(String str, String message) {
        check(str == null || str.trim().length() <= 0, message);
    }

    public static void isNotEmpty(Collection collection, String message) {
        check(collection != null && collection.size() > 0, message);
    }

    public static void isEmpty(Collection collection, String message) {
        check(collection == null || collection.size() == 0, message);
    }

    public static void isNotEmpty(Map map, String message) {
        check(map != null && map.size() > 0, message);
    }

    public static void isEmpty(Map map, String message) {
        check(map == null || map.size() == 0, message);
    }

    public static void isPositive(Integer number, String message) {
        check(number != null && number.compareTo(0) > 0, message);
    }

    public static void isPositive(Long number, String message) {
        check(number != null && number.compareTo(0L) > 0, message);
    }

    public static void isPositive(Double number, String message) {
        check(number != null && number.compareTo(0.0) > 0, message);
    }

    public static void isPositive(Float number, String message) {
        check(number != null && number.compareTo(0.0F) > 0, message);
    }

    public static void contains(Collection collection, Object value,String message) {
        check(collection != null && collection.contains(value), message);
    }

    public static void containsKey(Map map, Object key,String message) {
        check(map!=null && map.containsKey(key), message);
    }

    public static void containsValue(Map map, Object value,String message) {
        check(map!=null && map.containsValue(value), message);
    }
}
